﻿using System;
using FluentNHibernate;
using Framework.Repository.Conventions;
using Rhino.Mocks;
using Xunit;

namespace Framework.Tests.Repository
{
    internal class Entity
    {
    }

    public class CustomForeignKeyConventionTestable : CustomForeignKeyConvention
    {
        public string GetKeyNameTestable(Member property, Type type)
        {
            return GetKeyName(property, type);
        }
    }

    public class ForeignKeyConventionTest
    {
        private readonly CustomForeignKeyConventionTestable target;
        private readonly MockRepository mockRepository;

        public ForeignKeyConventionTest()
        {
            mockRepository = new MockRepository();
            memberMock = mockRepository.StrictMock<Member>();
            target = new CustomForeignKeyConventionTestable();
        }

        private readonly Member memberMock;

        [Fact]
        public void When_using_relation_ForeignKey_repect_convention()
        {
            memberMock.Expect(x => x.Name).Return("pouet");
            mockRepository.ReplayAll();
            Assert.Equal("pouet_FK", target.GetKeyNameTestable(memberMock, typeof(Entity)));
            mockRepository.VerifyAll();
        }

        [Fact]
        public void When_using_relation_with_null_member_ForeignKey_repect_convention()
        {
            Assert.Equal("Entity_FK", target.GetKeyNameTestable(null, typeof (Entity)));
        }
    }
}